package crivia.ecp.carry.em;

import crivia.ecp.ECPExecuter;
import crivia.ecp.carry.html.X;
import crivia.ecp.carry.html.form.Input;
import crivia.ecp.common.ECR;
import crivia.time.carry.Day;

public class DayPicker extends Input {
	
	public DayPicker() {}
	
	public DayPicker(String key) {
		setKey(key);
	}
	
	public DayPicker(String key, Day value) {
		setKey(key);
		setValue(value.toString());
	}
	
	public DayPicker(String key, String value) {
		setKey(key);
		setValue(value);
	}
	
	public DayPicker(ECPExecuter page, String key) {
		setKey(key);
		setValue(ECR.ns(page.rp(key)));
	}

	public DayPicker(String key, String value, String requirdString) {
		setKey(key);
		setValue(value);
		setRequirdString(requirdString);
	}

	public DayPicker(String key, Day value, String requirdString) {
		setKey(key);
		setValue(value.toString());
		setRequirdString(requirdString);
	}

	public DayPicker(ECPExecuter page, String key, String requirdString) {
		setKey(key);
		setValue(ECR.ns(page.rp(key)));
		setRequirdString(requirdString);
	}
	
	@Override
	protected String regScript() {
		EditerController controller = new EditerController(
				getScriptKey(), EditerController.Type.TimePicker
				, ECR.ns(getDefaultValue()), null
				, isRequird(), ECR.ns(getRequirdString()), getRequirdStringLevel());
		return X.JavaSctipt("_E.editer.create("+controller
				.setRequirdStringScript(requirdStringScript)+");"
			+"if('function'==typeof window._beautyDate)_beautyDate(null,'','');") + "";
	}

	@Override
	protected void beforeToString() {
		addAttr("_dpname", getKey());
		addAttr("name", getScriptKey());
	}
	@Override
	public String toString() {
		setCssClass("wuiDate");
		addAttr("type", Type_Hidden);
		X.hide(this);
		return super.toString();
	}
	
	@Override
	public Input textarea(String width, String height) {return this;}
	
}
